import json

import numpy as np
import matplotlib.pyplot as plt

# 防止中文乱码
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签SimHei
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

# 读取文件
path_no_pretrain = r"D:\Project\multimoding\res\CLIP_linear_probe\res_0625_3090\no_pretrain\json\evaluate_acc.json"
path_pretrain_8000 = r"D:\Project\multimoding\res\CLIP_linear_probe\res_0625_3090\pretrain_8000\json\evaluate_acc.json"
path_pretrain_9580 = r"D:\Project\multimoding\res\CLIP_linear_probe\res_0625_3090\pretrain_9580\json\evaluate_acc.json"
path_pretrain_14000 = r"D:\Project\multimoding\res\CLIP_linear_probe\res_0625_3090\pretrain_14000\json\evaluate_acc.json"

with open(path_no_pretrain, 'r') as f1, open(path_pretrain_8000, 'r') as f2, open(path_pretrain_9580, 'r') as f3, open(path_pretrain_14000, 'r') as f4:
    model1 = json.load(f1)
    model2 = json.load(f2)
    model3 = json.load(f3)
    model4 = json.load(f4)[:20]

# 计算统计量
mean1, mean2, mean3 = np.mean(model1), np.mean(model2), np.mean(model3)
std1, std2, std3 = np.std(model1), np.std(model2), np.std(model3)
max1, max2, max3 = np.max(model1), np.max(model2), np.max(model3)

min1, min2, min3 = np.min(model1), np.min(model2), np.min(model3)



# 打印结果
print(f"no_pretrain - 平均精度: {mean1:.4f}, 标准差: {std1:.4f}, 最高精度: {max1:.4f}, 最低精度: {min1:.4f}")
print(f"pretrain_8000 - 平均精度: {mean2:.4f}, 标准差: {std2:.4f}, 最高精度: {max2:.4f}, 最低精度: {min2:.4f}")
print(f"pretrain_9580 - 平均精度: {mean3:.4f}, 标准差: {std3:.4f}, 最高精度: {max3:.4f}, 最低精度: {min3:.4f}")

# 绘制折线图
plt.figure(figsize=(12, 6))
plt.plot(model1, label='no_pretrain', marker='o')
plt.plot(model2, label='pretrain_2000', marker='x')
plt.plot(model3, label='pretrain_8000', marker='v')
plt.plot(model4, label='pretrain_14000', marker='s')
plt.xlabel('epoch')
plt.ylabel('acc')
plt.legend()
plt.grid(True)
plt.savefig(r'D:\Project\multimoding\res\CLIP_linear_probe\res_0625_3090\res_0705.png')
